function cdc()
{
	var _self = this;
	this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
		      .getService(Components.interfaces.nsIPrefBranch);

	function getPref(name)
	{
		var type = _self.prefs.getPrefType(name);
		if (type == _self.prefs.PREF_STRING)
			return _self.prefs.getCharPref(name);
		else if (type == _self.prefs.PREF_INT)
			return _self.prefs.getIntPref(name);
		else if (type == _self.prefs.PREF_BOOL)
			return _self.prefs.getBoolPref(name);
		else 
			return 0;
	}

	function setPref(name, value)
	{
		var type = _self.prefs.getPrefType(name);
		if (type == _self.prefs.PREF_STRING)
			_self.prefs.setCharPref(name, value);
		else if (type == _self.prefs.PREF_INT)
			_self.prefs.setIntPref(name, value);
		else if (type == _self.prefs.PREF_BOOL)
			_self.prefs.setBoolPref(name, value);
		else 
			_self.prefs.setCharPref(name, value);
	}

	function get(id)
	{
		return document.getElementById(id);
	}
	function showContextMenu(e)
	{
		get("context-cleardnscache").hidden = gContextMenu.onImage;
	}

	this.onMenuItemCommand = function(e) 
	{
		var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
		//promptService.alert(window, this.strings.getString("helloMessageTitle"),
		//		this.strings.getString("helloMessage"));

		var name = "network.dnsCacheExpiration";
		var v = 3600;
		if(! _self.prefs.prefHasUserValue(name))
			setPref(name, v);
		else 
			v = getPref(name);
		var ret = "Get dns cache expire: " + v + "\n";
		setPref(name, 0);
		ret += "Set dns cache expire to: " + getPref(name) + "\n";
		setPref(name, v);
		ret += "Restore dns cache expire to: " +  getPref(name);

		if( getPref("extensions.cleardnscache.debug") ) {
			promptService.alert(window, "Notice", ret);
		}
	}

	this.onToolbarButtonCommand = function(e) {
		// just reuse the function above.  you can change this, obviously!
		_self.onMenuItemCommand(e);
	}
	this.onLoad = function(e)
	{
		this.init = true;
		this.strings = '';
		var menu = get('contentAreaContextMenu');
		menu.addEventListener("popupshowing", showContextMenu, false);
	}
}

var c = new cdc();
window.addEventListener("load", function(e) {	c.onLoad(e); }, false);
